<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<!--User: xulf Date: 2018/7/20 Time: 14:29-->
<link th:href="@{/css/labelColor.css}" rel="stylesheet">
<body>
<form id="update" role="form" method="post" action="user/update/password">
    <div class="form-group">
        <label for="userName">用户名<span>*</span></label>
        <input class="form-control" id="userName" name="userName" type="text"
               th:value="${data.userName}"
               placeholder="请输入用户名"/>
    </div>
    <div class="form-group">
        <label for="password">原始密码<span>*</span></label>
        <input class="form-control" id="password" name="password" type="password"
               placeholder="请输入原始密码"/>
    </div>
    <div class="form-group">
        <label for="newPassword">新密码<span>*</span></label>
        <input class="form-control" id="newPassword" name="newPassword" type="password"
               placeholder="请输入新密码"/>
    </div>
    <div class="form-group">
        <label for="newPassWordAgain">确认密码<span>*</span></label>
        <input class="form-control" id="newPassWordAgain" name="newPassWordAgain" type="password"
               placeholder="请确认新密码"/>
    </div>
</form>
<script th:src="@{/js/helper/disableEnterKey.js}"></script>
<script th:inline="javascript">
    <![CDATA[
    $(function () {
        $('#update').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                password: {
                    message: '密码验证失败',
                    validators: {
                        notEmpty: {
                            message: '原始密码不能为空'
                        },
                        stringLength:{
                            min:6,
                            max:16,
                            message:"密码长度在6-16之间"
                        }
                    }
                },
                userName: {
                    message: '用户名验证失败',
                    validators: {
                        notEmpty: {
                            message: '用户名不能为空'
                        }
                    }
                },

                newPassword: {
                    message: '验证失败',
                    validators: {
                        notEmpty: {
                            message: '新密码不能为空'
                        },
                        stringLength:{
                            min:6,
                            max:16,
                            message:"密码长度在6-16之间"
                        }
                    }
                },

                newPassWordAgain: {
                    message: '确认验证失败',
                    validators: {
                        notEmpty: {
                            message: '确认不能为空'
                        },
                        identical:{
                            field:"newPassword",
                            message:"两次密码输入不一致"
                        },
                        stringLength:{
                            min:6,
                            max:16,
                            message:"密码长度在6-16之间"
                        }
                    }
                },

            }
        });
        // 绑定dialog的确定按钮的监听事件
        $("#btnOk", window.top.document).click(function () {
            var bootstrapValidator = $("#update", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                var url = $("#update", window.top.document).attr('action');
                var myData = JSON.stringify({
                    "oldPassWord": $("#password").val(),
                    "newPassWord": $("#newPassword").val(),
                });
                $.ajax({
                    contentType:
                        "application/json",
                    type:
                        'POST',
                    url: url,
                    data: myData,
                    success:
                        function (result) {
                            // $('.modal-dialog', window.top.document).parent('div').remove()
                            // $('body', window.top.document).find('.modal-backdrop').remove();
                            // jquery 调用刷新当前操作的table页面的refresh方法
                            // $(window.parent.document).contents().find(".tab-pane.fade.active.in iframe")[0].contentWindow.doQuery();
                            activeTabBodyReset();
                            if (result.success) {
                                layer.msg('修改成功', {icon: 1, time: 2000})
                            }
                            else if(!result.success){
                                window.Ewin.alert({message: result.errMsg})
                            }
                        },
                    error: function (status) {
                        window.Ewin.alert({message: status.status + ':修改数据失败!'});
                    }
                });
            }
        });
    })
    ]]>
</script>
<script th:src="@{/layer/layer.js}"></script>
</body>
</html>